package com.renjianbo.project.common.model;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
public class Rest<T> implements Serializable{

	private static final long serialVersionUID = 5952861126789622536L;

    @ApiModelProperty(value="状态码：【｛200：操作成功｝，｛400：参数错误｝，｛401：用户认证失败｝，｛403：服务器不处理｝，｛500：服务器错误｝】")
	private Integer code;
    @ApiModelProperty(value="消息")
	private String message;
    @ApiModelProperty(value="数据")
	private T data;

    public static <T> Rest<T> success(T t){
        Rest<T> rest = new Rest<>();
        rest.setCode(200);
        rest.setData(t);
        rest.setMessage("success");

        return rest;
    }

    public static <T> Rest<T> success(){
        Rest<T> rest = new Rest<>();
        rest.setCode(200);
        rest.setData(null);
        rest.setMessage("success");

        return rest;
    }

    public static <T> Rest<T> warning(String desc){
        Rest<T> rest = new Rest<>();
        rest.setCode(403);
        rest.setData(null);
        rest.setMessage(desc);

        return rest;
    }

    public static <T> Rest<T> warning(Integer code, String desc){
        Rest<T> rest = new Rest<>();
        rest.setCode(code);
        rest.setData(null);
        rest.setMessage(desc);

        return rest;
    }

    public static <T> Rest<T> warning(Integer code, String desc, T t){
        Rest<T> rest = new Rest<>();
        rest.setCode(code);
        rest.setData(t);
        rest.setMessage(desc);

        return rest;
    }

    public static <T> Rest<T> error(){
        Rest<T> rest = new Rest<>();
        rest.setCode(500);
        rest.setData(null);
        rest.setMessage("error");

        return rest;
    }

    public static <T> Rest<T> error(String desc){
        Rest<T> rest = new Rest<>();
        rest.setCode(500);
        rest.setData(null);
        rest.setMessage(desc);

        return rest;
    }

    public static <T> Rest<T> error(String desc, T t){
        Rest<T> rest = new Rest<>();
        rest.setCode(500);
        rest.setData(t);
        rest.setMessage(desc);

        return rest;
    }

}

	
